package com.weishi.project.training.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.weishi.framework.aspectj.lang.annotation.Log;
import com.weishi.framework.aspectj.lang.enums.BusinessType;
import java.util.Arrays;
import com.weishi.project.training.domain.Team;
import com.weishi.project.training.service.ITeamService;
import com.weishi.framework.web.controller.BaseController;
import com.weishi.framework.web.domain.AjaxResult;
import com.weishi.common.utils.poi.ExcelUtil;
import com.weishi.framework.web.page.TableDataInfo;

/**
 * teamController
 */
@RestController
@RequestMapping("/training/team")
public class TeamController extends BaseController {

    @Autowired
    private ITeamService teamService;

    /**
     * 查询team列表
     */
    @PreAuthorize("@ss.hasPermi('training:team:list')")
    @GetMapping("/list")
    public TableDataInfo list(Team team) {
        startPage();
        List<Team> list = teamService.selectTeamList(team);
        return getDataTable(list);
    }

    /**
     * 查询所有team列表
     */
    @PreAuthorize("@ss.hasPermi('training:team:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll(Team team) {
        List<Team> list = teamService.selectTeamList(team);
        return AjaxResult.success(list);
    }

    /**
     * 获取team详细信息
     */
    @PreAuthorize("@ss.hasPermi('training:team:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(teamService.getById(id));
    }

    /**
     * 新增team
     */
    @PreAuthorize("@ss.hasPermi('training:team:add')")
    @Log(title = "team", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Team team) {
        teamService.save(team);
        return AjaxResult.success();
    }

    /**
     * 修改team
     */
    @PreAuthorize("@ss.hasPermi('training:team:edit')")
    @Log(title = "team", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Team team) {
        teamService.updateById(team);
        return AjaxResult.success();
    }

    /**
     * 删除team
     */
    @PreAuthorize("@ss.hasPermi('training:team:remove')")
    @Log(title = "team", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        teamService.removeByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }
    
}